#! /bin/bash

# Author: Faisal Abu-Nimeh
# Mod Date: 20140306
# Description: (runs on controller workstation)  After acquiring data, this scripts copies all graws from all mm* to ~/grawData/YYYYMMDDHHMMSS. It also copies the controller's workstation ~/GET-20140217/runtime/* files to store the configuration for this run.

copyTime=`date +%Y%m%d%H%M%S`
targetIP=192.168.41.2
targetDIR=grawData/$copyTime
configDir=$targetDIR/xconfigFiles

if [ "$#" -lt 1 ]; then
    echo "Usage: $0 DIRECTORY"
    echo "e.g. $0 GET-20140217"
    exit 1
fi


echo "Checking status for all mm servers"

for i in `seq 0 9`;
do
	echo "mm$i graws being copied"
	mkdir -p ~/$targetDIR/mm$i
	ssh mm$i.local "scp /Users/attpc/$1/runtime/*.graw $targetIP:/Users/attpc/$targetDIR/mm$i; mkdir -p /Users/attpc/$1/runtime/previousGraw; mv  /Users/attpc/$1/runtime/*.graw  /Users/attpc/$1/runtime/previousGraw"
	echo " "
	echo " "
done  

echo "Done copying graw files to ~/$targetDIR/mm*"

# copy configuration files
mkdir -p ~/$configDir
cp /Users/attpc/$1/runtime/* ~/$configDir

echo "Done copying configuration files to $configDir"

exit 1
